import Vue from 'vue';
import Vuex from 'vuex';

Vue.use(Vuex);

export default new Vuex.Store({
  state: {
    token: uni.getStorageSync('token') || '',
    isLogin: uni.getStorageSync('isLogin') || false, // 登录状态
    loginDialogShow: false, // 登录弹窗
    userInfo: uni.getStorageSync('userInfo') || null // 用户信息
  },
  mutations: {
    // 关闭登录弹窗
    closeLoginDialog(state) {
      state.loginDialogShow = false;
    },
    showLoginDialog(state) {
      state.loginDialogShow = true;
    },
    // 存储用户信息
    saveUserInfo(state, data) {
      state.userInfo = data;
    },
    // 存储token
    saveUserToken(state, token) {
      state.token = token;
      state.isLogin = true;
    },
    // 退出
    loginout() {
      this.token = null;
      this.isLogin = false;
      this.userInfo = null;
      uni.clearStorageSync();
    }
  },
  actions: {},
  getters: {}
})